class ListNode(object):
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next


def listToNode(list):
    node = ListNode()
    cur = node
    for num in list:
        cur.next = ListNode(num)
        cur = cur.next

    return node.next


def nodeToList(node):
    res = []
    while node:
        res.append(node.val)
        node = node.next
    return res
